package com.lwbldy.modules.student.controller;


import com.github.pagehelper.PageHelper;
import com.lwbldy.common.tools.PageUtils;
import com.lwbldy.common.tools.R;
import com.lwbldy.modules.student.domain.PreLog;
import com.lwbldy.modules.student.domain.PreRegistration;
import com.lwbldy.modules.student.service.IPreLogService;


import com.lwbldy.modules.student.service.MajorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;


@Controller
@Api(tags = "")
@RequestMapping("/student/prelog")
public class PreLogController {

    /**
         * Describe: 基础路径
         * */
    private static String MODULE_PATH = "student/prelog/";


    @Resource
    private IPreLogService preLogService;
    @Resource
    private MajorService majorService;

    @GetMapping("main")
    @ApiOperation(value="获取列表视图")
    public String main( ModelMap map ){
        map.put("majorList",majorService.queryList(null));
        return MODULE_PATH + "main";
    }


    @GetMapping("list")
    @ApiOperation(value="获取推送列表数据")
    @ResponseBody
    public R data(@RequestParam(value = "page", defaultValue = "1") Integer page,
                  @RequestParam(value = "limit", defaultValue = "15") Integer limit,
                  @RequestParam(value = "stuIdcard", required = false) String stuIdcard,
                  @RequestParam(value = "schoolId",required = false) Integer schoolId,
                  @RequestParam(value = "status",required = false) Integer status,
                  @RequestParam(value = "majorId",required = false) Integer majorId
    ){
        PageHelper.startPage(page, limit);
        PreLog preLog = null;
        if(stuIdcard != null && !"".equals(stuIdcard) || status != null || schoolId != null || majorId != null){
            preLog = new PreLog();
            preLog.setStuIdcard(stuIdcard);
            preLog.setStatus(status);
            preLog.setSchoolId(schoolId);
            preLog.setMajorId(majorId);
        }


        List<PreLog> brandList = preLogService.selectList(preLog);
        return PageUtils.restPage(brandList);
    }

    @GetMapping("preLogInfo")
    @ApiOperation(value="获取学生缴费记录")
    public String preLogInfo(String idCard,ModelMap map){
        map.put("preLogList",preLogService.queryByIdCard(idCard));
        return MODULE_PATH + "preLogInfo";
    }

    @PostMapping("update")
    @ApiOperation(value="修改数据")
    @ResponseBody
    public R update(PreLog preLog){
        int result = preLogService.updateById(preLog);
        return R.resultRow(result);
    }

}
